const state = {
    list: [], // 需要管理的状态数据
}

const mutations = {
    removeById(state, id) {
        console.log(id);
        state.list = state.list.filter(item => {
            return item.id !== id
        })
    },
    initList(state, data) {
        state.list = data
    },
    changeSelect(state, item) {
        item.isSelect != item.isSelect
    },
    selectAll(state) {
        state.list.forEach(item => {
            item.isSelect = true
        })
    },
    selectCancle(state) {
        state.list.forEach(item => {
            item.isSelect = false
        })
    }
}
const getters = {
    totalPrice: state => {
        let total = 0
        state.list.filter(item => {
            return item.isSelect
        }).forEach(item => {
            total += item.price * item.count
        })
        return total
    }
}
const actions = {
    initListData(context, data) {
        context.commit('initList', data)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    getters,
    actions
}